import qdarkstyle
from PyQt5.QtWidgets import QMessageBox

from qtpy import QtCore
from src.user.AllToyInform_UI import Ui_Form
from PyQt5 import QtWidgets
import mysql.connector


class AllToyInform_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb,parent=None):
        super(AllToyInform_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.LoginSignal=False
        self.mydb=mydb
        self._translate = QtCore.QCoreApplication.translate
        self.tableWidget.setEditTriggers(self.tableWidget.NoEditTriggers)
    def Table_Data1(self, i, j, data):
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setItem(i, j, item)
        item = self.tableWidget.item(i, j)
        item.setText(self._translate("Form", str(data)))

    def myTable_init1(self):
        cur = self.mydb.cursor()
        cur.execute('SELECT * FROM usertoy_select')  # 将数据从数据库中拿出来
        total = cur.fetchall()
        col_result = cur.description
        self.row = cur.rowcount  # 取得记录个数，用于设置表格的行数
        self.vol = len(total[0])  # 取得字段数，用于设置表格的列数
        col_result = list(col_result)
        a = 0
        self.tableWidget.setColumnCount(self.vol)
        self.tableWidget.setRowCount(self.row)
        for i in col_result:  # 设置表头信息，将mysql数据表中的表头信息拿出来，放进TableWidget中
            item = QtWidgets.QTableWidgetItem()
            self.tableWidget.setHorizontalHeaderItem(a, item)
            item = self.tableWidget.horizontalHeaderItem(a)
            item.setText(self._translate("Form", i[0]))
            a = a + 1
        total = list(total)  # 将数据格式改为列表形式，其是将数据库中取出的数据整体改为列表形式
        for i in range(len(total)):  # 将相关的数据
            total[i] = list(total[i])  # 将获取的数据转为列表形式
        for i in range(self.row):
            for j in range(self.vol):
                self.Table_Data1(i, j, total[i][j])

    def getMydb(self,mydb):
        self.mydb=mydb








